package com.sun.baizhi.workqueue;

import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.sun.baizhi.utils.RabbitMQUtil;

import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.TimeoutException;

public class Producer {
    public static void main(String[] args) {
        String host = "123.56.180.207";
        Integer port = 5672;
        String virtualHost = "/ems";
        String userName = "ems";
        String passWord = "123";
        Connection connection = null;
        Channel channel = null;
        try {
            connection = RabbitMQUtil.getConnection(host, port, virtualHost, userName, passWord);
            channel = connection.createChannel();
            channel.queueDeclare("work",true,false,false,null);
            for (int i = 0; i < 10; i++) {
                channel.basicPublish("","work",null,(i + "hello work queue").getBytes(StandardCharsets.UTF_8));

            }
        } catch (IOException e) {
            e.printStackTrace();
        } catch (TimeoutException e) {
            e.printStackTrace();
        }finally {
            RabbitMQUtil.close(connection,channel);
        }
    }
}
